from typing import Optional

from pydantic import Field

from owl_ai.domain.chat_entity import ChatMessage, Chat
from owl_common.base.model import BaseEntity


class ChatDTO(BaseEntity):
    id: Optional[int] = Field(description="会话ID", default=None)
    name: Optional[str] = Field(description="会话名称", default=None)
    agent_id: Optional[int] = Field(description="代理ID", default=None)
    create_by: Optional[int] = Field(description="创建人", default=None)
    update_by: Optional[int] = Field(description="更新人", default=None)

    def toAIChat(self):
        chat = Chat()
        chat.id = self.id
        chat.name = self.name
        chat.agent_id = self.agent_id
        chat.create_by = self.create_by
        chat.update_by = self.update_by
        return chat


class ChatMessageDTO(BaseEntity):
    chat_id: int = Field(description="会话ID")
    message_id: int = Field(description="消息ID")
    content: str = Field(description="内容")
    files: list = Field(description="文件列表")

    def toMessageEntity(self):
        chat_message = ChatMessage()

        chat_message.chat_id = self.chat_id
        chat_message.id = self.message_id
        chat_message.content = self.content
        chat_message.files = self.files

        return chat_message
